//
// Created by 紫霄 on 2020/4/6.
//

#ifndef LEETCODE_04_H
#define LEETCODE_04_H
#include <vector>
using namespace std;
class Solution {
public:
  bool findNumberIn2DArray(vector<vector<int>> &matrix, int target) {
    if (matrix.size()) {
      int m = matrix[0].size() - 1;
      int n = 0;
      while (n < matrix.size() && m > -1) {
        if (target > matrix[n][m]) {
          ++n;
        } else if (target < matrix[n][m]) {
          --m;
        } else {
          return true;
        }
      }
      return false;
    }

    return false;
  }
};

#endif // LEETCODE_04_H
